package com.erp.erp_servers.CustomerShare.imp;

import com.erp.erp_dao.CustomerShare.ICustomerShareDAO;
import com.erp.erp_entitys.CustomerShare.CustomerShareEntity;
import com.erp.erp_entitys.CustomerShare.CustomerShareExample;
import com.erp.erp_servers.CustomerShare.ICustomerShareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @ClassName ImpCustomerShareService
 * @Description TODO
 * @Author songjizhen
 * @Date 2020-06-29 20:05
 * @Version 1.0
 */
@Service
public class ImpCustomerShareService implements ICustomerShareService {

    @Autowired
    ICustomerShareDAO customerShareDAO;
    @Override
    public long countByExample(CustomerShareExample example) {
        return customerShareDAO.countByExample(example);
    }

    @Override
    public int deleteByExample(CustomerShareExample example) {
        return customerShareDAO.deleteByExample(example);
    }

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return customerShareDAO.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(CustomerShareEntity record) {
        return customerShareDAO.insert(record);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int insertSelective(CustomerShareEntity record) {
        CustomerShareExample example=new CustomerShareExample();
        CustomerShareExample.Criteria criteria = example.createCriteria();
        criteria.andCodeEqualTo(record.getCode());
        criteria.andTypeEqualTo(record.getType());
        int num=customerShareDAO.deleteByExample(example);
        record.setUsercode(record.getUsercode().replace("\"",""));
        if(record.getUsercode().equals("")){
            return num;
        }else{
            return customerShareDAO.insertSelective(record);
        }

    }

    @Override
    public List<CustomerShareEntity> selectByExample(CustomerShareExample example) {
        return customerShareDAO.selectByExample(example);
    }

    @Override
    public CustomerShareEntity selectByPrimaryKey(Integer id) {
        return customerShareDAO.selectByPrimaryKey(id);
    }

    @Override
    public int updateByExampleSelective(CustomerShareEntity record, CustomerShareExample example) {
        return customerShareDAO.updateByExampleSelective(record,example);
    }

    @Override
    public int updateByExample(CustomerShareEntity record, CustomerShareExample example) {
        return customerShareDAO.updateByExample(record,example);
    }

    @Override
    public int updateByPrimaryKeySelective(CustomerShareEntity record) {
        return customerShareDAO.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(CustomerShareEntity record) {
        return customerShareDAO.updateByPrimaryKey(record);
    }
}
